package com.an;

public class HmoeWork_3 {
    public static void main(String[] args) {

        String name="Hello world Xinxin";
        String newname=C.sFormat(name);
        System.out.println(name);
        System.out.println("格式化后");
        System.out.println(newname);

    }
}

/**
 * 要求
 * JACK Mack Dod输出Dog ,JACK.M
 */


class C{
    public static String sFormat(String name){
         //1.先得把名字分开
        //2.中间名字首字母换成大写
        //3.反序 加,加.
        //通过空格位置将他们分开,substring截取

        int firstIndex=name.indexOf(" ");
        int lastIndex=name.lastIndexOf(" ");
        int length=name.length();
//        System.out.println(firstIndex);
//        System.out.println(lastIndex);
        //截取
        String firstname=name.substring(0,firstIndex);
        String lastname=name.substring(lastIndex+1,length);
       String secondname=name.substring(firstIndex+1,lastIndex);//不需要第二部分的所有名字
//        System.out.println(firstname);
//        System.out.println(secondname);
//        System.out.println(lastname);
        secondname=secondname.toUpperCase();
      char ch=secondname.charAt(0);
      //String ch2=ch+"";
      //拼接
        return lastname+","+firstname+"."+ch;
    }

}
